<ul class="tabSet">
	<li class="close">Close Panel</li>
	<li class="back">&laquo; Back</li>
</ul>

<h1>SQL Explain</h1>
<div class="container">
	<dl>
		<dt>Query:</dt>
		<dd><pre class="sql-query">{{ sql|escape|linebreaksbr }}</pre></dd>
		<dt>Parameters:</dt>
		<dd>{% if params %}{{ params|join:", "|escape }}{% else %}&nbsp;{% endif %}</dd>
	</dl>
</div>
<table class="data sortable" border="0" cellspacing="0" cellpadding="0"> 
	<thead>
		<tr>
		{% for header in headers %}
			{% if forloop.first %}
				<th>{{ header|title|escape }}</th>
			{% else %}
				{% if forloop.last %}
					<th>{{ header|title|escape }}</th>
				{% else %}
					<th>{{ header|title|escape }}</th>
				{% endif %}
			{% endif %}
		{% endfor %}
		</tr>
	</thead>
	<tbody>
	{% for row in explain %}
		<tr class="{% cycle 'even' 'odd' %}">
		{% for value in row %}
			<td>{{ value|escape }}</td>
		{% endfor %}
		</tr>
	{% endfor %}
	</tbody>
</table>
{% if indexes %}
<h1>Indexes</h1>
<table class="data sortable" border="0" cellspacing="0" cellpadding="0"> 
	<thead>
		<tr>
			<th>Table</th>
			<th>Name</th>
			<th>Columns</th>
			<th>Type</th>
			<th>Cardinality</th>
		</tr>
	</thead>
	<tbody>
	{% for table, rows in indexes.iteritems %}
		{% for name, row in rows.iteritems %}
			<tr class="{% cycle 'even' 'odd' %}">
				<td>{{ table|escape }}</td>
				<td>{{ name|escape }}</td>
				<td>{{ row.0|join:", "|escape }}</td>
				<td>{{ row.1|escape }}</td>
				<td>{{ row.2 }}</td>
			</tr>
		{% endfor %}
	{% endfor %}
	</tbody>
</table>
{% endif %}

<h1>Traceback</h1>
<div class="container">
	<ul class="traceback" id="sql_explain_traceback">
	</ul>
</div>
<script type="text/javascript">
	var ref = jQuery('.sql-query');
	ref.html(ref.text().replace(/(UNION|ANALYZE|MATCH|AGAINST|ALL|ASC|AS|ALTER|AND|ADD|AUTO_INCREMENT|BETWEEN|BINARY|BOTH|BY|BOOLEAN|CHANGE|CHECK|COLUMNS|COLUMN|CROSS|CREATE|DATABASES|DATABASE|DATA|DELAYED|DESCRIBE|DESC|DISTINCT|DELETE|DROP|DEFAULT|ENCLOSED|ESCAPED|EXISTS|EXPLAIN|FIELDS|FIELD|FLUSH|FOR|FOREIGN|FUNCTION|FROM|GROUP|GRANT|HAVING|IGNORE|INDEX|INFILE|INSERT|INNER JOIN|INTO|IDENTIFIED|IN|IS|IF|JOIN|KEYS|KILL|KEY|LEADING|LIKE|LIMIT|LINES|LOAD|LOCAL|LOCK|LOW_PRIORITY|LEFT|LANGUAGE|MODIFY|NATURAL|NOT|NULL|NEXTVAL|OPTIMIZE|OPTION|OPTIONALLY|ORDER BY|OUTFILE|OR|OUTER|ON|PROCEEDURE|PROCEDURAL|PRIMARY|READ|REFERENCES|REGEXP|RENAME|REPLACE|RETURN|REVOKE|RLIKE|RIGHT|SHOW|SONAME|STATUS|STRAIGHT_JOIN|SELECT|SETVAL|SET|TABLES|TEMINATED|TO|TRAILING|TRUNCATE|TABLE|TEMPORARY|TRIGGER|TRUSTED|UNIQUE|UNLOCK|USE|USING|UPDATE|VALUES|VARIABLES|VIEW|WITH|WRITE|WHERE|ZEROFILL|TYPE|XOR)/g, '<br /><span class="hilight">$1</span>').substr(6));

	var traceback = jQuery('#sql_explain_traceback');
	jQuery(locals.stack).each(function(index)
	{
		traceback.append('<li>'+this[0]+':'+this[1]+' <span class="hilight">('+this[2]+')</span></li>');
	});

	traceback.find('li:odd').addClass('odd');
</script>